import { Component, OnInit } from '@angular/core';
import { Router } from '@angular/router';
import {LoginService} from '../../service/login.service';
import {AuthService} from '../../service/auth.service';
import * as $ from 'jquery';

@Component({
  selector: 'app-login',
  templateUrl: './login.component.html',
  styleUrls: ['./login.component.css']
})
export class LoginComponent implements OnInit {
  account: any = {
    code: '', password: ''
  };
  message: string;

  constructor(
    public router: Router,
    public loginService: LoginService,
    public authService: AuthService
  ) {
    this.setMessage();
  }

  setMessage() {
    this.message = 'Logged ' + (this.authService.isLoggedIn ? 'in' : 'out');
  }

  companyLogin() {
    this.loginService.companyLogin(this.account);
  }

  talentLogin() {
    this.loginService.talentLogin(this.account);
  }

  findPasswordInCompany() {
    this.loginService.findPasswordInCompany(this.account);
  }

  findPasswordInTalent() {
    this.loginService.findPasswordInTalent(this.account);
  }
  logout() {
    this.loginService.logout();
    this.setMessage();
  }

  ngOnInit() {
    $('.screenbg ul li').each(function() {
      $(this).css('opacity', '0');
    });
    $('.screenbg ul li:first').css('opacity', '1');
    let index = 0;
    let t;
    let li = $('.screenbg ul li');
    let number = li.length;
    function change() {
      li.css('visibility', 'visible');
      li.eq(index).siblings().animate({opacity: 0}, 3000);
      li.eq(index).animate({opacity: 1}, 3000);
    }
    function show() {
      index = index + 1;
      if (index <= number - 1) {
        change();
      } else {
        index = 0;
        change();
      }
    }
    t = setInterval(show, 8000);
    // 根据窗口宽度生成图片宽度
    let width = $(window).width();
    $('.screenbg ul img').css('width', width + 'px');
  }

}
